package com.simon.train.common.context;

import com.simon.train.common.vo.MemberLoginVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * member会员信息的线程本次存储
 * 将登录成功后的会员信息通过本地线程的方式存储 方便后续各种模块需要使用到会员id等信息时直接获取
 */
public class LoginMemberContext {
    private static final Logger LOG = LoggerFactory.getLogger(LoginMemberContext.class);

    private static ThreadLocal<MemberLoginVO> member = new ThreadLocal<>();

    public static MemberLoginVO getMember() {
        return member.get();
    }

    public static void setMember(MemberLoginVO member) {
        LoginMemberContext.member.set(member);
    }

    /**
     * 获取对应的会员id信息
     * @return
     */
    public static Long getId() {
        try {
            return member.get().getId();
        } catch (Exception e) {
            LOG.error("获取登录会员信息异常", e);
            throw e;
        }
    }

}
